package labox.innovation.gameserver.model.actor.instance;

import labox.innovation.config.Config;
import labox.innovation.gameserver.network.serverpackets.ActionFailed;
import labox.innovation.gameserver.network.serverpackets.InventoryAndMerchantPakcet;
import labox.innovation.gameserver.templates.chars.NpcTemplate;

/**
 * NPC商人
 * @author Frank
 *
 */
public class FuzeMerchantInstance extends FuzeNpcInstance {

	public FuzeMerchantInstance(long objectId, NpcTemplate template) {
		super(objectId, template);
	}
	
	/**
	 * 下发背包中信息
	 * @param player
	 */
	private void showInventoryWindow(FuzePcInstance player) {
		float storeBuyRate = player.getTemplate().getBaseShopBuyRate();  //-- 商店购买系数
		float storeSellRate = player.getTemplate().getBaseShopSellRate();  //-- 商店出售系数
		int karma = player.getKarma();  //-- 获取当前玩家身上的善恶值

		if (karma >= Config.KARMAREDSSET) {
			storeBuyRate = (float)(Config.KARMABASE + karma)/Config.KARMABASE;
			storeSellRate = (float)(Config.KARMABASE - karma)/Config.KARMABASE;
		}

		player.sendPacket(ActionFailed.STATIC_PACKET);
		player.sendPacket(new InventoryAndMerchantPakcet(player, getNpcId(), storeBuyRate, storeSellRate));
		return;
	}
	
	@Override
	public void onBypassFeedback(FuzePcInstance player, String command) {
		if (command.startsWith("GetMerchantList")) {
			showInventoryWindow(player);
		}
		super.onBypassFeedback(player, command);
	}
}
